<?php

class Admin_Backup_RestoreAction extends BlogAdminBaseAction
{
    public function executeWrite(AgaviRequestDataHolder $rd)
    {
        $backup_file = $rd->getParameter('backup_file');
        if (substr($backup_file, 0, 1) !== DIRECTORY_SEPARATOR) {
            $backup_file = DIRECTORY_SEPARATOR . $backup_file;
        }
        
        $vm = $this->getContainer()->getValidationManager();
        // check that backup file exists
        if (!is_file($backup_file)) {
            $vm->setError('backup_file', 'File not found.');
            return 'Error';
        }
        
        /* @var $backup_model Admin_BackupsModel */
        $backup_model = $this->getContext()->getModel('Backups', 'Admin');
        
        try {
            $backup_model->doRestoreAll($backup_file);
        } catch (WereWordRestoreException $e) {
            $vm->setError('general', $e->getMessage());
            return 'Error';
        }
        
        return 'Success';    
    }
    
    
	/**
	 * Returns the default view if the action does not serve the request
	 * method used.
	 *
	 * @return     mixed <ul>
	 *                     <li>A string containing the view name associated
	 *                     with this action; or</li>
	 *                     <li>An array with two indices: the parent module
	 *                     of the view to be executed and the view to be
	 *                     executed.</li>
	 *                   </ul>
	 */
	public function getDefaultViewName()
	{
		return 'Input';
	}
}

?>